home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Quads.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  6.8 KB  |  211 lines

  1. /*
  2. //   (C) COPYRIGHT International Business Machines Corp. 1993
  3. //   All Rights Reserved
  4. //   Licensed Materials - Property of IBM
  5. //   US Government Users Restricted Rights - Use, duplication or
  6. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. //
  8.  
  9. //
  10. // Permission to use, copy, modify, and distribute this software and its
  11. // documentation for any purpose and without fee is hereby granted, provided
  12. // that the above copyright notice appear in all copies and that both that
  13. // copyright notice and this permission notice appear in supporting
  14. // documentation, and that the name of I.B.M. not be used in advertising
  15. // or publicity pertaining to distribution of the software without specific,
  16. // written prior permission. I.B.M. makes no representations about the
  17. // suitability of this software for any purpose.  It is provided "as is"
  18. // without express or implied warranty.
  19. //
  20. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. // Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28. //
  29. */
  30.  
  31. #include <math.h>
  32. #include "Quads.h"
  33.  
  34. #define sq(val) ((val)*(val))
  35.  
  36. #undef offset
  37. #define offset(v) offsetof(Quads,v)
  38.  
  39. static InfoItem QuadsInfo[] = {
  40. #define INC_REASON INFO_ITEM_ARRAY
  41. #include "Quads.h"
  42. #undef INC_REASON
  43. };
  44. #include <malloc.h>
  45.  
  46. QuadsPtr new_Quads()
  47. {
  48.     QuadsPtr this = (QuadsPtr)malloc(sizeof(Quads));
  49.     CheckMalloc(this);
  50.     new_Polygonal((PolygonalPtr)this);
  51.     SetDefaults((TestPtr)this, QuadsInfo);
  52.     this->testType = QuadsTest;
  53.     this->primitiveType = GL_QUADS;
  54.     this->vertsPerFacet = 4;
  55.     this->usecPixelPrint = " microseconds per pixel with Quads";
  56.     this->ratePixelPrint = " pixels per second with Quads";
  57.     this->usecPrint = " microseconds per Quad";
  58.     this->ratePrint = " Quads per second";
  59.     /* Set virtual functions */
  60.     this->delete = delete_Quads;
  61.     this->Layout = Quads__Layout;
  62.     this->Copy = Quads__Copy;
  63.     return this;
  64. }
  65.  
  66. void delete_Quads(TestPtr thisTest)
  67. {
  68.     QuadsPtr this = (QuadsPtr)thisTest;
  69.     delete_Polygonal(thisTest);
  70. }
  71.  
  72. TestPtr Quads__Copy(TestPtr thisTest)
  73. {
  74.     QuadsPtr this = (QuadsPtr)thisTest;
  75.     QuadsPtr newQuads = new_Quads();
  76.     FreeStrings((TestPtr)newQuads);
  77.     *newQuads = *this;
  78.     CopyStrings((TestPtr)newQuads, (TestPtr)this);
  79.     return (TestPtr)newQuads;
  80. }
  81.  
  82. void Quads__Layout(VertexPtr thisVertex)
  83. {
  84.     QuadsPtr this = (QuadsPtr)thisVertex;
  85.     const double pi=3.141592654;
  86.     double ndcSize, width, height, radius;
  87.     double theta, theta0, deltaTheta;
  88.     GLfloat x, y;
  89.     GLfloat *src, *dst;
  90.     GLfloat *newTraversalData;
  91.     int numFrontIn, numFrontOut, numFrontClip;
  92.     int numBackIn, numBackOut, numBackClip;
  93.     int frontIn, frontOut, frontClip, backIn, backOut, backClip;
  94.     GLfloat face=1.0;
  95.     int i, j;
  96.     GLfloat facingFront = this->facingFront;
  97.     GLfloat facingBack  = this->facingBack;
  98.     int numObjects  = this->numObjects;
  99.     GLfloat acceptObjs  = this->acceptObjs;
  100.     GLfloat rejectObjs  = this->rejectObjs;
  101.     GLfloat clipObjs     = this->clipObjs;
  102.     int   windowDim   = min(this->environ.windowWidth, this->environ.windowHeight);
  103.     int   orientation = this->orientation;
  104.     GLfloat size        = this->size;
  105.     int   objsPerBgnEnd  = this->objsPerBgnEnd;
  106.  
  107.     /* Use Vertex__Layout() and Vertex__orientation to choose layout */
  108.     this->vertsPerBgnEnd = objsPerBgnEnd * this->vertsPerFacet;
  109.     this->facetsPerBgnEnd = objsPerBgnEnd;
  110.  
  111.     /* Figure front facing/back facing stuff */
  112.     if (fabs(1.0 - facingFront - facingBack) > .01) {
  113.         printf("FrontFacing + BackFacing not equal to 1\n");
  114.     exit(1);
  115.     }
  116.     numFrontIn = floor((GLfloat)numObjects * acceptObjs * facingFront + 0.5);
  117.     numFrontOut = floor((GLfloat)numObjects * rejectObjs * facingFront + 0.5);
  118.     numFrontClip = floor((GLfloat)numObjects * clipObjs * facingFront + 0.5);
  119.     numBackIn = floor((GLfloat)numObjects * acceptObjs * facingBack + 0.5);
  120.     numBackOut = floor((GLfloat)numObjects * rejectObjs * facingBack + 0.5);
  121.     numBackClip = floor((GLfloat)numObjects * clipObjs * facingBack + 0.5);
  122.     numFrontIn += numObjects - numFrontIn - numFrontOut - numFrontClip
  123.                              - numBackIn - numBackOut - numBackClip;
  124.     frontIn = frontOut = frontClip = backIn = backOut = backClip = 0;
  125.     
  126.     /* Figure polygon dimensions given polygon size in pixels and number of sides */
  127.     ndcSize = size/(double)windowDim/(double)windowDim*4.0;
  128.     width = sqrt(ndcSize/this->aspect);
  129.     height = ndcSize/width;
  130.     radius = sqrt(sq(height/2.0) + sq(width/2.0));
  131.     deltaTheta = atan(height/width);
  132.  
  133.     /* Use Vertex__Layout() to get polygon centers */
  134.     this->layoutPoints = numObjects;
  135.     switch (orientation) {
  136.     case Vertical:
  137.     case Horizontal:
  138.             this->layoutPadding = max(width,height)/2.;
  139.         break;
  140.     case Random:
  141.             this->layoutPadding = radius;
  142.         break;
  143.     }
  144.     this->layoutPadding += (1. + (this->antiAlias!=Off))/
  145.                            (float)windowDim;
  146.     Vertex__Layout(thisVertex);
  147.  
  148.     /* Allocate necessary data */
  149.     src = this->traversalData;
  150.     newTraversalData = (GLfloat*)malloc(numObjects * 4 * 2 * sizeof(GLfloat));
  151.     CheckMalloc(newTraversalData);
  152.     dst = newTraversalData;
  153.  
  154.     /* Figure initial theta position for orientation */
  155.     switch (orientation) {
  156.     case Horizontal:
  157.         theta0 = deltaTheta;
  158.         break;
  159.     case Vertical:
  160.         theta0 = deltaTheta + pi/2.0;
  161.         break;
  162.     case Random:
  163.             mysrand(15000);
  164.         break;
  165.     }
  166.  
  167.     /* Generate those vertices around the point centers */
  168.     for (i=0; i<numObjects; i++) {
  169.     x = *src++;
  170.     y = *src++;
  171.     if (orientation == Random)
  172.             theta0 = 2.0*pi*(double)myrand()/(double)MY_RAND_MAX;
  173.     if ((x==-1 || x==1) && (-1<=y && y<=1) || (y==-1 || y==1) && (-1<=x && x<=1)) {
  174.         /* The vertex is clipped (on the viewport boundary) */
  175.         if (frontClip < numFrontClip) {
  176.         frontClip++;
  177.         face = 1.0;
  178.         } else {
  179.         backClip++;
  180.         face = -1.0;
  181.         }
  182.     } else if (-1<=x && x<=1 && -1<=y && y<=1) {
  183.         /* The vertex is in the viewport */
  184.         if (frontIn < numFrontIn) {
  185.         frontIn++;
  186.         face = 1.0;
  187.         } else {
  188.         backIn++;
  189.         face = -1.0;
  190.         }
  191.     } else {
  192.         /* The vertex is outside the viewport */
  193.         if (frontOut < numFrontOut) {
  194.         frontOut++;
  195.         face = 1.0;
  196.         } else {
  197.         backOut++;
  198.         face = -1.0;
  199.         }
  200.     }
  201.     theta = theta0;
  202.     for (j=0; j<4; j++) {
  203.         *dst++ = radius * cos(theta) + x;
  204.         *dst++ = radius * sin(theta) + y;
  205.         theta += face*((j&1) ? (2.0*deltaTheta) : (pi-2.0*deltaTheta));
  206.     }
  207.     }
  208.     free(this->traversalData);
  209.     this->traversalData = newTraversalData;
  210. }
  211.